﻿/*
 * @Autor: PK
 */

using System.Xml;

namespace ShkSimulation.core.util.osm {
	
	public class Node : BaseItem {
		public long Id {get; private set; }
		public double Latitude { get; private set; }
		public double Longitude { get; private set; }
		public string Name { get; private set; }
		public string PublicTransport { get; private set; }
    
		// implicit conversion between OsmNode and Vector3
		//使得node可以像Vector3一样运算
		public static implicit operator Way (Node node) {
			return new Way(null);
		}
    
		public Node(XmlNode node) {
			Id = GetAttribute<long>("id", node.Attributes);
			Latitude = GetAttribute<double>("lat", node.Attributes);
			Longitude = GetAttribute<double>("lon", node.Attributes);
			XmlNodeList tags = node.SelectNodes("tag");
			if (tags != null) {
				foreach (XmlNode t in tags) {
					string key = GetAttribute<string>("k", t.Attributes);
					if ("public_transport".Equals(key)) {
						PublicTransport = GetAttribute<string>("v", t.Attributes);
					}
					if ("name".Equals(key)) {
						Name = GetAttribute<string>("v", t.Attributes);
						break;
					}
					if ("name:zh".Equals(key)) {
						Name = GetAttribute<string>("v", t.Attributes);
						break;
					}
					if ("name:en".Equals(key)) {
						Name = GetAttribute<string>("v", t.Attributes);
						break;
					}
				}
			}
		}

	}
}